package walasp.proto;

import java.util.Date;

import android.database.Cursor;

/**
 * 
 * The object which stores all information about a task (due date, name, 
 * description etc), and upon which all task-related actions are performed.
 * 
 */
public class Task {
	// task column name variables:
	// to be used when making selects as select args
	public static final String TASK_COLUMN_TID = "TID";
	public static final String TASK_COLUMN_PARENTTID = "ParentTID";// 0 means
																	// top level

	public static final String TASK_COLUMN_TASKNAME = "TaskName";
	public static final String TASK_COLUMN_TASKCONTENT = "TaskContent";
	public static final String TASK_COLUMN_CREATIONDATE = "CreationDate";
	public static final String TASK_COLUMN_STARTDATE = "StartDate";
	public static final String TASK_COLUMN_DUEDATE = "DueDate";
	public static final String TASK_COLUMN_COMPLTEDDATE = "CompletedDate";
	public static final String TASK_COLUMN_STATUS = "Status";
	public static final String TASK_COLUMN_PRIORITY = "Priority";
	public static final String TASK_COLUMN_CONTACTS = "Contacts";

	// to be used for column lookups when retrieving rows
	public static final int TASK_COLUMN_INT_TID = 0;
	public static final int TASK_COLUMN_INT_PARENTTID = 1;
	public static final int TASK_COLUMN_INT_TASKNAME = 2;
	public static final int TASK_COLUMN_INT_TASKCONTENT = 3;
	public static final int TASK_COLUMN_INT_CREATIONDATE =4;
	public static final int TASK_COLUMN_INT_STARTDATE = 5;
	public static final int TASK_COLUMN_INT_DUEDATE = 6;
	public static final int TASK_COLUMN_INT_COMPLTEDDATE = 7;
	public static final int TASK_COLUMN_INT_STATUS = 8;
	public static final int TASK_COLUMN_INT_PRIORITY = 9;
	public static final int TASK_COLUMN_INT_CONTACTS = 10;

	private int TID;
	private int pTID;
	private String TaskName;
	private String TaskContent;
	private int Priority;
	private String Status;
	private String Contacts;
	private Date CreationDate;
	private Date StartDate;
	private Date DueDate;
	private Date CompletedDate;

	/**
	 *Creates a new Task object with the parameters provided 
	 *@param _TID
	 *			The ID of the Task
	 *@param _pTID
	 *			The ID of the Task's parent Task, if applicable - currently
	 *			unused
	 *@param _TaskName
	 *			The name of the Task
	 *@param _TaskContent
	 *			The description of the Task
	 *@param _Priority	
	 *			The Task's priority level - currently unused
	 *@param _Status
	 *			The status of the Task (Active, Pending, Finished, Cancelled)
	 *@param _Contacts
	 *			The contacts that are linked to the Task.  Currently limited to 
	 *			1 contact per task
	 *@param _CreationDate
	 *			The date that the Task was created
	 *@param _StartDate
	 *			The date from which the Task is Active - currently unused
	 *@param _DueDate
	 *			The date the task is due to be completed.
	 *@param _CompletedDate
	 *			The date the task is marked off as completed.
	 *@return a new Task object
	 */
	public Task(int _TID, int _pTID, String _TaskName, String _TaskContent,
			int _Priority, String _Status, String _Contacts,
			Date _CreationDate, Date _StartDate, Date _DueDate,
			Date _CompletedDate) {
		TID = _TID;
		pTID = _pTID;
		TaskName = _TaskName;
		TaskContent = _TaskContent;
		Priority = _Priority;
		Status = _Status;
		Contacts = _Contacts;
		CreationDate = _CreationDate;
		StartDate = _StartDate;
		DueDate = _DueDate;
		CompletedDate = _CompletedDate;

	}

	/**
	 * 
	 *Creates a Task object using the information represented by the cursor at its current position
	 *@param cur
	 *			A cursor generated from a Select * from TASKS query 
	 */
	public Task(Cursor cur) {

		TID = cur.getInt(Task.TASK_COLUMN_INT_TID);
		pTID = cur.getInt(Task.TASK_COLUMN_INT_PARENTTID);
		TaskName = cur.getString(Task.TASK_COLUMN_INT_TASKNAME);
		TaskContent = cur.getString(Task.TASK_COLUMN_INT_TASKCONTENT);
		Priority = cur.getInt(Task.TASK_COLUMN_INT_PRIORITY);
		Status = cur.getString(Task.TASK_COLUMN_INT_STATUS);
		Contacts = cur.getString(Task.TASK_COLUMN_INT_CONTACTS);
		CreationDate = new Date(
				 cur.getLong(Task.TASK_COLUMN_INT_CREATIONDATE));
		StartDate = new Date( cur.getLong(Task.TASK_COLUMN_INT_STARTDATE));
		DueDate = new Date( cur.getLong(Task.TASK_COLUMN_INT_DUEDATE));
		CompletedDate = new Date(
				cur.getLong(Task.TASK_COLUMN_INT_COMPLTEDDATE));
		
	}
	
	/**
	 * Returns the string representation of the Task i.e. the Task name.
	 * @return the string representation of the Task object
	 */
	public String toString(){
		return TaskName;
	}

	public int getTID() {
		return TID;
	}

	/**
	 * Sets the Task ID of the task
	 * @param tID
	 * 			the ID of the task
	 */
	public void setTID(int tID) {
		TID = tID;
	}

	/**
	 * Gets the parent Task ID of the task - currently unused
	 * @return the Task ID of the task's parent
	 */
	public int getpTID() {
		return pTID;
	}

	/**
	 * Sets the parent Task ID of the task - currently unused
	 * @param pTID
	 * 			the Task ID of the task's parent
	 */
	public void setpTID(int pTID) {
		this.pTID = pTID;
	}

	/**
	 * Gets the name of the task
	 * @return the name of the task
	 */
	public String getTaskName() {
		return TaskName;
	}

	/**
	 * Sets the name of the task
	 * @param taskName
	 * 			the name of the task
	 */
	public void setTaskName(String taskName) {
		TaskName = taskName;
	}

	/**
	 * Gets the content/description of the task
	 * @return the String containing the content/description of the task
	 */
	public String getTaskContent() {
		return TaskContent;
	}
	
	/**
	 * Sets the content/description of the task
	 * @param taskContent
	 * 			the String containing the content/description of the task
	 */
	public void setTaskContent(String taskContent) {
		TaskContent = taskContent;
	}

	/**
	 * Gets the priority of the task - currently unused
	 * @return the integer indicating the priority of the task
	 */
	public int getPriority() {
		return Priority;
	}

	/**
	 * Sets the priority of the task - currently unused
	 * @param priority
	 * 			the integer indicating the priority of the task
	 */
	public void setPriority(int priority) {
		Priority = priority;
	}

	/**
	 * Gets the status of the task
	 * @return the String object describing the task status.  One of ["Active",
	 * 			"Pending", "Completed", "Cancelled"].
	 */
	public String getStatus() {
		return Status;
	}

	/**
	 * Sets the status of the task
	 * @param status
	 * 			the String object describing the task status.  One of ["Active",
	 * 			"Pending", "Completed", "Cancelled"].
	 */
	public void setStatus(String status) {
		Status = status;
	}

	/**
	 * Gets the contacts linked to this task.
	 * @return the contacts linked to this task.
	 */
	public String getContacts() {
		return Contacts;
	}

	/**
	 * Sets the contacts linked to this task.
	 * @param contacts
	 * 			the contacts to be linked to this task.
	 */
	public void setContacts(String contacts) {
		Contacts = contacts;
	}

	/**
	 * Gets the creation date of the task
	 * @return the Date object describing the creation date
	 */
	public Date getCreationDate() {
		return CreationDate;
	}

	/**
	 * Sets the creation date of the task
	 * @param creationDate
	 * 			the Date object describing the creation date
	 */
	public void setCreationDate(Date creationDate) {
		CreationDate = creationDate;
	}

	/**
	 * Gets the start date of the task
	 * @return the Date object describing the start date
	 */
	public Date getStartDate() {
		return StartDate;
	}

	/**
	 * Sets the start date of the task
	 * @param startDate
	 * 			the Date object describing the start date
	 */
	public void setStartDate(Date startDate) {
		StartDate = startDate;
	}

	/**
	 * Gets the due date of the task
	 * @return the Date object describing the due date
	 */
	public Date getDueDate() {
		return DueDate;
	}

	/**
	 * Sets the due date of the task
	 * @param dueDate
	 * 			the Date object describing the due date
	 */
	public void setDueDate(Date dueDate) {
		DueDate = dueDate;
	}

	/**
	 * Gets the completed date of the task
	 * @return the Date object describing the completion date
	 */
	public Date getCompletedDate() {
		return CompletedDate;
	}

	/**
	 * Sets the completed date of the task
	 * @param completedDate
	 * 			the Date object describing the completion date
	 */
	public void setCompletedDate(Date completedDate) {
		CompletedDate = completedDate;
	}

}
